from flask import request,redirect,session
import functools,hashlib
def token_logined(func):
    @functools.wraps(func)
    def inner(*args,**kwargs):
        token = request.headers.get('token')
        if not token:
            return "login faild"
        return func(*args,**kwargs)
    return inner

def user_auth(func):
    @functools.wraps(func)
    def inner(*args,**kwargs):
        uid = session.get('uid')
        role = session.get('role')
        # token = session.get('token')
        if not uid and role != 'user':
            return "Access Not Allow"
        return func(*args,**kwargs)
    return inner

def admin_auth(func):
    @functools.wraps(func)
    def inner(*args,**kwargs):
        uid = session.get('uid')
        role = session.get('role')
        if not uid and role != 'admin':
            return "Access Not Allow"
        return func(*args,**kwargs)
    return inner
# def cookie_logined(func):
#     @functools.wraps(func)
#     def inner(*args,**kwargs):
#         token = request.cookies.get('user')
#         if not token:
#             return "not logined"
#         passwd = "a6c07ae20716c913c42fb6cf943d9c61"
#         if token != passwd:
#             return "auth failed"
#         else:
#             return func(*args,**kwargs)
#     return inner
